#include "threadPool.h"
char base_addr[200]="/home/lh/project1";
int connectmysql(MYSQL *mysql)
{
    if (!mysql) {
        fprintf(stderr, "mysql_init() 失败\n");
        return 1;
    }
    mysql=mysql_real_connect(mysql,"localhost","root","123","OnlineStorage",0,NULL,0);
    printf("11111\n");
    if (!mysql) {
        fprintf(stderr, "连接失败: %s\n", mysql_error(mysql));
        return 1;                                                   
    }
    return 0;
}

int threadPoolInit(threadPool_t *pthreadPool,int workerNum){
    tidArrInit(&pthreadPool->tidArr, workerNum);
    taskQueueInit(&pthreadPool->taskQueue);
    pthread_mutex_init(&pthreadPool->mutex, NULL);
    pthread_cond_init(&pthreadPool->cond, NULL);
    pthreadPool->exitFlag = 0;
    return 0;
}


int recvCommandPacket(int netfd,int *cmd,int *length,char *addr)
{
    bzero(addr,strlen(addr));
    int j=0;
    recv(netfd,cmd,sizeof(int),MSG_WAITALL);
    recv(netfd,length,sizeof(int),MSG_WAITALL);
    if(*length==0)
    {
        *length=1;
        j=1;
    }
    recv(netfd,addr,*length,MSG_WAITALL);
    if(j==1)
    {
        *length=0;
    }

    return 0;
}

int recvn(int sockfd, void *buf, ssize_t length){
    char *p = (char *)buf;//char* 是因为偏移以1个字节为单位
    ssize_t cursize = 0;
    while(cursize < length){
        ssize_t sret = recv(sockfd,p+cursize,length-cursize,0);
        cursize += sret;
    }
    return 0;
}




